package com.m2bshop.shop.service.TransactionService;

import com.github.pagehelper.PageHelper;
import com.m2bshop.shop.dao.TransactionMapper;
import com.m2bshop.shop.pojo.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
public class TransactionServiceImpl implements TransactionService{

    @Autowired
    TransactionMapper transactionMapper;
    @Autowired
    private PageHelper ph;

    @Override
    public List<Transaction> getAllTransaction(int userid, int page,int pageSize) {
        ph.startPage(page,pageSize);
        return transactionMapper.getAll(userid);
    }

    @Override
    public void insertNewTransaction(double money,String type,int userid){
        Date date=new Date();
        DateFormat dateformat = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
        String strdate = dateformat.format(date);//日期转换
        Transaction transaction=new Transaction(strdate,money,type,userid);
        System.out.println("金额为"+money);
        transactionMapper.Insert(transaction);

    }

    @Override
    public List<Transaction> getTransaction(int userid) {
        return transactionMapper.getOne(userid);
    }

    @Override
    public List<Transaction> adminGetAll(int page,int pageSize) {
        ph.startPage(page,pageSize);
        return transactionMapper.getByAdmin();
    }


}
